/**
 * @description 用户部门管理
 * @author zhu_liangyu
 * @since 2021/12/23
 */

import { OrgServiceApi } from "./_org";
import { AxiosResponse } from "axios";
import service from "@/api";
import { SYSTEM_CONFIG } from "@/config/system";
import { objectToUrlParams } from "@/utils/common";

class UnitServiceApi extends OrgServiceApi {
  /**
   * 下载excel附件信息
   * @param templateId 附件模板id
   * @returns
   */
  downloadExcelTemplate(type: string): Promise<AxiosResponse<Blob>> {
    let url = this.baseUrl + "/downloadTemplate?type=" + type;
    return service.post(url, undefined, {
      responseType: "blob",
      timeout: SYSTEM_CONFIG.DOWNLOAD_FILE_TIMEOUT
    });
  }

  getImportExcelUrl() {
    return this.baseUrl + "/importUnitData";
  }
  getById(pk: string, params?: any): Promise<AxiosResponse<any>> {
    let url = this.baseUrl + "/id/" + pk;
    return service.get(url, { params });
  }
  giveInsert(bean: any, params?: any): Promise<AxiosResponse<any>> {
    let url = this.baseUrl + "/";
    url += objectToUrlParams(params, true);
    return service.post(url, bean);
  }
  /**
   * 获取部门的上级部门
   * @param unitId 部门id
   * @returns
   */
  getUnitandParentUnits(unitId: string) {
    let url = this.baseUrl + "/getUnitandParentUnits";
    return service.get(url, { params: { unitId } });
  }
}
const unitServiceApi = new UnitServiceApi("/UnitService");

export default unitServiceApi;
